// Copyright 2013 Ronald Schlenker, www.technewlogic.de.
// 
// This file is part of Byond.
// 
// Byond is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 2 of the License, or
// (at your option) any later version.
// 
// Byond is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with Byond.  If not, see <http://www.gnu.org/licenses/>.
using System;
using System.Windows.Input;
using Byond.HostObjects;
using Byond.Messages;

namespace Byond
{
	public class KeyboardCallbackManager
	{
		private readonly CallbackControllerCache _callbackControllerCache = new CallbackControllerCache();

		private readonly CallbackController<KeyEventArgs> _keyDownCallbackController = new CallbackController<KeyEventArgs>();
		internal CallbackController<KeyEventArgs> KeyDownCallbackController { get { return _keyDownCallbackController; } }

		private readonly CallbackController<KeyEventArgs> _keyUpCallbackController = new CallbackController<KeyEventArgs>();
		internal CallbackController<KeyEventArgs> KeyUpCallbackController { get { return _keyUpCallbackController; } }

		public void HandleMessage(EnsembleStoppedMessage message)
		{
			_callbackControllerCache.Clear();
			_keyDownCallbackController.Clear();
			_keyUpCallbackController.Clear();
		}

		public void OnKeyDown(KeyEventArgs args)
		{
			_callbackControllerCache.Store(args, _keyDownCallbackController);
		}

		public void OnKeyUp(KeyEventArgs args)
		{
			_callbackControllerCache.Store(args, _keyUpCallbackController);
		}

		public void Raise()
		{
			_callbackControllerCache.Raise();
		}
	}
}